<template>
  <div class="container">
    <div @click="launch('mini')">
      <i class="icon icon_mini"></i>
    </div>
    <div @click="launch('max')" v-show="!isMax">
      <i class="icon icon_max"></i>
    </div>
    <div @click="launch('restore')" v-show="isMax">
      <i class="icon icon_restore"></i>
    </div>
    <div @click="launch('close')">
      <i class="icon icon_close"></i>
    </div>
  </div>
</template>

<script>
import { ipcRenderer, remote } from "electron";
export default {
  computed: {
    isMax() {
      return this.$store.state.window.maximized;
    },
  },
  methods: {
    launch(flag) {
      let win = remote.getCurrentWindow();
      switch (flag) {
        case "close":
          win.close();
          break;
        case "max":
          win.maximize();
          break;
        case "restore":
          win.unmaximize();
          break;
        case "mini":
          win.minimize();
          break;
      }
    },
  },
  created() {
    //监听主进程传入的消息,反馈给vuex进行状态管理
    ipcRenderer.on("window:max", (e, max) => {
      this.$store.commit("SET_WINDOW_MAXIMIZED", max);
    });
  },
};
</script>

<style scoped lang="less">
@import url(../../assets/codeIcon/icon.css);
.container {
  -webkit-app-region: no-drag;
  height: 100%;
  display: flex;
  div {
    &:hover {
      background-color: rgba(200, 200, 200, 0.1);
    }
    &:nth-last-child(1):hover{
      background-color: rgba(255,0,0,.5);
    }
    height: 100%;
    width: 66px;
    display: flex;
    align-items: center;
    justify-content: center;
    i {
      font-size: 18px;
    }
  }
}
</style>